package org.jhub1.system.xmpp.commands;

import java.util.ArrayList;

public class RequestMessage {
	private String command;
	private ArrayList<String> params = new ArrayList<String>();
	private String jid;
	private String uname;
	private String resource;	
	
	public RequestMessage(String message, String jid) {
		this.jid = jid;
		String[] jidElements = jid.split("\\/");
		int jels = jidElements.length;
		switch (jels) {
		case 1:
			this.uname = jidElements[0];
			break;
		default:
			this.uname = jidElements[0];
			this.resource = jidElements[1];
			break;
		}
		
		String[] par = message.split("\\ ");
		int pl = par.length;
		switch (pl) {
		case 1:
			this.command = par[0];
			break;
		default:
			this.command = par[0];
			int c = 0;
			for(String p: par) {
				if(c != 0) {
					this.params.add(p);
				}
				c++;
			}
			break;
		}
	}

	public String getCommand() {
		return command;
	}

	public String getUName() {
		return uname;
	}

	public String getResource() {
		return resource;
	}
	
	public void setCommand(String command) {
		this.command = command;
	}

	public ArrayList<String> getParams() {
		return params;
	}

	public String getParamsString() {
		StringBuilder sb = new StringBuilder();
		for(String param : params) {
			sb.append(param).append(" ");
		}
		return sb.toString();
	}
	
	public void setParams(ArrayList<String> params) {
		this.params = params;
	}

	public String getJid() {
		return jid;
	}

	public void setJid(String jid) {
		this.jid = jid;
	}
}
